package org.hdax.service.impl;

import org.hdax.dao.BillDao;
import org.hdax.entity.Bill;
import org.hdax.service.BillService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service(value = "userService")
public class BillServiceImpl implements BillService {

    @Autowired
    private BillDao billDao;

    public void setBillDao(BillDao billDao) {
        this.billDao = billDao;
    }

    @Override
    public List<Bill> getAllBills() {
        return billDao.getAll();
    }

    @Override
    public Integer getCount() {
        return billDao.getCount();
    }

    @Override
    public Integer getCountAndC(Bill condition) {
        return billDao.getCountAndC(condition);
    }

    @Override
    public List<Bill> getByPage(Integer offset, Integer limit) {
        return billDao.getByPage(offset, limit);
    }

    @Override
    public List<Bill> getByPage(Integer offset, Integer limit, Bill condition) {
        return billDao.getByPageAndC(condition,offset,limit);
    }

    @Override
    public boolean deleteById(Integer id) {
        boolean isDelete = false;
        try {
            billDao.deleteEntity(id);
            isDelete = true;
        }catch (Exception e){
            System.out.println(e.getMessage());
            isDelete = false;
        }
        return isDelete;
    }

    @Override
    public boolean batchDelete(List<Integer> ids) {
        boolean isDelete = false;
        try {
            billDao.batchDelEntity(ids);
            isDelete = true;
        }catch (Exception e){
            System.out.println(e.getMessage());
            isDelete = false;
        }
        return isDelete;
    }

    @Override
    public boolean saveBill(Bill bill) {
        boolean isSave = false;
        try {
            billDao.saveEntity(bill);
            isSave = true;
        }catch (Exception e){
            e.printStackTrace();
            System.out.println(e.getMessage());
            isSave = false;
        }
        return isSave;
    }

    @Override
    public Bill getById(Integer id) {
        return billDao.getById(id);
    }

    @Override
    public boolean updateBill(Bill bill) {
        boolean isUpdate = false;
        try {
            billDao.updateEntity(bill);
            isUpdate = true;
        }catch (Exception e){
            e.printStackTrace();
            System.out.println(e.getMessage());
            isUpdate = false;
        }
        return isUpdate;
    }
}
